package com.adapter;

import java.util.ArrayList;
import java.util.List;

import com.adapter.VideoListAdapter.GetCSDNLogoTask;
import com.adapter.VideoListAdapter.ViewHolder;
import com.entity.Navigation;
import com.videoplayer.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NavAdapter extends BaseAdapter {

	private List<Navigation> list = new ArrayList<Navigation>();
	private ViewHolder viewHolder;
	private Context c;
	private int flag = 0;

	public NavAdapter(Context c, List<Navigation> list) {
		this.c = c;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setFlag(int i) {
		flag = i;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {

		if (convertView == null) {
			convertView = View.inflate(c, R.layout.navigation_item, null);
			viewHolder = new ViewHolder();
			viewHolder.title = (TextView) convertView
					.findViewById(R.id.tv_title);
			viewHolder.imgTitle = (ImageView) convertView
					.findViewById(R.id.iv_img);
			viewHolder.lyItem = (LinearLayout) convertView
					.findViewById(R.id.ly_item);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (list != null) {
			if (arg0 == flag)
				viewHolder.lyItem.setBackgroundResource(R.drawable.selected);
			else
				viewHolder.lyItem.setBackgroundResource(R.drawable.unselected);
			viewHolder.title.setText(list.get(arg0).getTitle());
			viewHolder.imgTitle.setImageDrawable(list.get(arg0).getTitleImg());
			// new GetCSDNLogoTask().execute(list.get(arg0).getvImg());
			// viewHolder.imgTitle.setImageBitmap(getHttpBitmap(videoList.get(arg0).getvImg()));
		}
		return convertView;
	}

	static class ViewHolder {
		private TextView title;
		private ImageView imgTitle;
		private LinearLayout lyItem;
	}

}
